home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 4 / Info_Mac IV CD-ROM (Pacific HiTech Inc.)(August 1994).iso / Development / Source / MSG Demo 1.4.source Folder / Demo ƒ / Wipes reversed ƒ / Hilbert wipe reversed.c < prev    next >
Text File  |  1994-04-15  |  4KB  |  144 lines

  1. /**********************************************************************\
  2.  
  3. File:        Hilbert wipe reversed.c
  4.  
  5. Purpose:    Graphic effect from offscreen bitmap to main window (on
  6.             screen).  See comments below for more description.
  7.  
  8. This program is free software; you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation; either version 2 of the License, or
  11. (at your option) any later version.
  12.  
  13. This program is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. GNU General Public License for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with this program in a file named "GNU General Public License".
  20. If not, write to the Free Software Foundation, 675 Mass Ave,
  21. Cambridge, MA 02139, USA.
  22.  
  23. \**********************************************************************/
  24.  
  25. #include "timing.h"
  26.  
  27. /* This fills the screen by a Hilbert space-filling curve, which is defined by
  28.    two mutually recursive drawing functions:
  29.    
  30.    X = left, Y, draw, right, X, draw, X, right, draw, Y, left
  31.    Y = right, X, draw, left, Y, draw, Y, left, draw, X, right
  32.    
  33.    Start by drawing X at the highest recursion level from the bottomleft of the
  34.    screen. (At recursion level 1, X and Y are null functions.)
  35.    
  36.    [Note that the procedure below actually draws the Hilbert curve flipped
  37.    horizontally on the screen, so it starts drawing at the bottomright and
  38.    works leftward.]
  39. */
  40.  
  41. #define    RecursionLevel    4
  42. #define CorrectTime 1
  43. #define theWindowHeight (boundsRect.bottom-boundsRect.top)
  44. #define theWindowWidth (boundsRect.right-boundsRect.left)
  45.  
  46. pascal void HilbertRecurseReversed(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect,
  47.     int level, int whichpattern, int* x, int* y);
  48. pascal short HilbertWipeReversed(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect);
  49.  
  50. typedef char    Hilby[11];
  51.  
  52. static Hilby    HilbertPattern[]=
  53. {
  54.     {
  55.         0x02,0x69,0x00,0x01,0x42,0x00,0x42,0x01,0x00,0x69,0x02
  56.     },
  57.     {
  58.         0x01,0x42,0x00,0x02,0x69,0x00,0x69,0x02,0x00,0x42,0x01
  59.     }
  60. };
  61.  
  62. static int            HilbertDirection;
  63. static int            vBlockSize;
  64. static int            hBlockSize;
  65. static RgnHandle    boundsRgn;
  66.  
  67. pascal void HilbertRecurseReversed(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr,
  68.     Rect boundsRect, int level, int whichpattern, int* x, int* y)
  69. {
  70.     int                i;
  71.     Rect            source;
  72.     
  73.     for (i=0; i<11; i++)
  74.     {
  75.         switch (HilbertPattern[whichpattern][i])
  76.         {
  77.             case 0x01:     /* turn left */
  78.                 HilbertDirection--;
  79.                 if (HilbertDirection<0) HilbertDirection=3;
  80.                 break;
  81.             case 0x02:     /* turn right */
  82.                 HilbertDirection++;
  83.                 if (HilbertDirection==4) HilbertDirection=0;
  84.                 break;
  85.             case 0x00:    /* draw */
  86.                 StartTiming();
  87.                 SetRect(&source, theWindowWidth-*x-hBlockSize, *y-vBlockSize,
  88.                     theWindowWidth-*x, *y);
  89.                 OffsetRect(&source, boundsRect.left, boundsRect.top);
  90.                 CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits),
  91.                                 &source, &source, 0, boundsRgn);
  92.                 switch (HilbertDirection)
  93.                 {
  94.                     case 0:
  95.                         *x+=hBlockSize;
  96.                         break;
  97.                     case 1:
  98.                         *y-=vBlockSize;
  99.                         break;
  100.                     case 2:
  101.                         *x-=hBlockSize;
  102.                         break;
  103.                     case 3:
  104.                         *y+=vBlockSize;
  105.                         break;
  106.                 }
  107.                 TimeCorrection(CorrectTime);
  108.                 break;
  109.             case 0x42:    /* call X */
  110.                 if (level>1)
  111.                     HilbertRecurseReversed(sourceGrafPtr,destGrafPtr,boundsRect,level-1,0,x,y);
  112.                 break;
  113.             case 0x69:    /* call Y */
  114.                 if (level>1)
  115.                     HilbertRecurseReversed(sourceGrafPtr,destGrafPtr,boundsRect,level-1,1,x,y);
  116.                 break;
  117.         }
  118.     }
  119. }
  120.  
  121. pascal short HilbertWipeReversed(GrafPtr sourceGrafPtr, GrafPtr destGrafPtr, Rect boundsRect)
  122. {
  123.     int            curx, cury;
  124.     int            answer, i;
  125.     
  126.     answer=1;
  127.     for (i=0; i<RecursionLevel; i++)
  128.         answer*=2;
  129.     vBlockSize=1+theWindowHeight/answer;    /* used to be 20 */
  130.     hBlockSize=1+theWindowWidth/answer;        /* used to be 32 */
  131.     HilbertDirection=0;
  132.     boundsRgn=NewRgn();
  133.     RectRgn(boundsRgn, &boundsRect);
  134.     cury=theWindowHeight;
  135.     curx=0;
  136.     HilbertRecurseReversed(sourceGrafPtr,destGrafPtr,boundsRect,RecursionLevel,0,&curx,&cury);
  137.     CopyBits(&(sourceGrafPtr->portBits), &(destGrafPtr->portBits),
  138.                 &boundsRect, &boundsRect, 0, 0L);  /* in case we missed any bits */
  139.     
  140.     DisposeRgn(boundsRgn);
  141.     
  142.     return 0;
  143. }
  144.